import axios from "axios";
import useDialogStore from "@/store/dialog";

const request = axios.create({
    baseURL: "/api",
    timeout: 5000
});

request.interceptors.request.use((config) => {
    //设置请求token
    const dialogStore = useDialogStore();
    if (dialogStore.userInfo) {
        config.headers.token = dialogStore.userInfo.token
    }
    return config
})

request.interceptors.response.use((success) => {
    return success.data
}, (err) => {
    return Promise.reject(new Error(err.message))
})

export default request
